const express = require('express')
require('dotenv').config()
const app = express()

const mongoose = require('mongoose')

mongoose.connect(process.env.DATABASE_URL, { 
  useNewUrlParser: true,
  useUnifiedTopology: true
})
const db = mongoose.connection
db.on('error', (error)=>{console.log(error)})
db.once('open', () => console.log('connected to database'))

// 设置我们的服务器以接受JSON
app.use(express.json())

const subScribersRouter = require('./routes/subscribers')
const categoryRouter = require('./routes/categories')
app.use('/subscribers', subScribersRouter)
app.use('/categories', categoryRouter)

app.listen(3000, ()=>{
  console.log('http://localhost:3000');
})